<template>
  <div class="register-page">
    <van-nav-bar title="面经注册" />
    <van-form @submit="onSubmit">
      <!-- 用户名 -->
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' },
        {pattern: /^\w{5,8}$/,message: '宝贝,用户名为3~8位哦~~~'}
        ]"
      />

      <!-- 密码 -->
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[
        { required: true, message: '请填写密码' },
        {pattern: /^\w{6,}/,message: '宝贝,密码至少得6位哦~~~'}
        ]"
      />
      <!-- 验证码 -->
      <!-- <van-field
        v-model="sms"
        center
        clearable
        name="code"
        label="短信验证码"
        placeholder="请输入短信验证码"
        :rules="[
        {required:false,message: '请输入验证码'},
        {pattern: /^\d{6}$/,message: '宝贝,请输入正确的验证码哦~~~'}
        ]"
      >
        <template #button>
          <van-button size="small" type="primary">发送验证码</van-button>
        </template>
      </van-field> -->
      <!-- 注册按钮 -->
      <div style="margin: 16px">
        <van-button color="pink" size="large" native-type="submit"
          >注册</van-button
        >
      </div>
    </van-form>
    <router-link class="link" to="/login">已有账号,去登录</router-link>
    <div class="picture">
      <img
        src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg2.huashi6.com%2Fimages%2Fresource%2F2021%2F08%2F02%2F9167257h5p0.png%3FimageMogr2%2Fquality%2F75%2Finterlace%2F1%2Fthumbnail%2F700x%26gt%3B%2Fformat%2Fjpeg&refer=http%3A%2F%2Fimg2.huashi6.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670246195&t=df8338dcd6e31bb60732d81050aa73c0"
        alt=""
      />
    </div>
  </div>
</template>

<script>
import { register } from '@/api/user'
export default {
  name: 'register-page',
  data () {
    return {
      username: '',
      password: ''
      // sms: ''
    }
  },
  methods: {
    async onSubmit (values) {
      const res = await register(values)
      console.log(res)
      this.$toast.success('注册成功')
      setTimeout(() => {
        this.$router.push('/login')
      }, 1000)
    }
  }
}
</script>

<style lang="less" scoped>
.link {
  color: #069;
  font-size: 12px;
  padding-right: 20px;
  float: right;
}
.picture {
  width: 200px;
  height: 300px;
}
img {
  width: 100%;
}
</style>
